package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.model.product.SpuSaleAttrValue;
import com.atguigu.gmall.product.mapper.BaseSpuSaleAttrValueMapper;
import com.atguigu.gmall.product.service.BaseSpuSaleAttrService;
import com.atguigu.gmall.product.mapper.BaseSpuSaleAttrMapper;
import com.atguigu.gmall.product.service.BaseSpuSaleAttrValueService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Dell
* @description 针对表【spu_sale_attr(spu销售属性)】的数据库操作Service实现
* @createDate 2022-05-18 20:35:26
*/
@Service
public class BaseSpuSaleAttrServiceImpl extends ServiceImpl<BaseSpuSaleAttrMapper, SpuSaleAttr>
implements BaseSpuSaleAttrService {

    @Autowired
    private BaseSpuSaleAttrValueMapper saleAttrValueMapper;

    @Override
    public List<SpuSaleAttr> getSaleAttrService(Long spuId) {
        QueryWrapper<SpuSaleAttr> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("spu_id",spuId);
        List<SpuSaleAttr> spuSaleAttrs = baseMapper.selectList(queryWrapper);
        for (SpuSaleAttr spuSaleAttr : spuSaleAttrs) {
            QueryWrapper<SpuSaleAttrValue> queryWrapperValue = new QueryWrapper<>();
            queryWrapperValue.eq("spu_id",spuId);
            queryWrapperValue.eq("base_sale_attr_id",spuSaleAttr.getBaseSaleAttrId());
            spuSaleAttr.setSpuSaleAttrValueList(saleAttrValueMapper.selectList(queryWrapperValue));
        }
        return spuSaleAttrs;
    }
}
